import Vue from 'vue'
import App from './App.vue'
import ElementUI from 'element-ui';
import router from '@/router/index'
import 'element-ui/lib/theme-chalk/index.css';


// import './assets/icons'
import axios from 'axios'
import store from './store'
import * as echarts from 'echarts';


import less from 'less'

import VueAMap from 'vue-amap';   //引入高德
VueAMap.initAMapApiLoader({
    key: '8351a411410ab3fc1dfb7574c4f9ad60',
    //插件集合
    plugin: [
        'AMap.Geolocation',  //定位空间，用来获取和展示用户主机所在的经纬度位置
        ' AMap.Autocomplete ',  //输入提示插件
        ' AMap.PlaceSearch ', //POI搜索插件
        ' AMap.Scale ',   //右下角缩略图插件，比例尺
        ' AMap.OverView ', //地图鹰眼插件
        ' AMap.ToolBar ',  //地图工具条
        ' AMap.MapType ',  //类别切换空间，实现默认图层与卫星图，实施交通层之间切换的控制
        ' AMap.PolyEditor ', //编辑 折线多边形
        ' AMap.CircleEditor ',
        "AMap.Geocoder"     //地图编码
    ]
});




Vue.use(less)

Vue.prototype.$echarts = echarts
Vue.prototype.$http = axios

// Vue.prototype.$websocket = "ws://127.0.0.1/websocket/"
Vue.prototype.$websocket = "ws://124.223.12.164/websocket/"

axios.defaults.baseURL = 'http://124.223.12.164'
// axios.defaults.baseURL = 'http://127.0.0.1'

// 添加请求拦截器
axios.interceptors.request.use((config) => {
    // 在发送请求之前做些什么
    if (!store.state.myToken) {
        return config
    }
    config.headers.Authorization = 'Bearer ' + store.state.myToken
    return config
})

function routerToIndex() {
    window.localStorage.removeItem("myToken")
    router.push("/")
}

// 添加响应拦截器
axios.interceptors.response.use(function (response) {
    if (response.data.code == 401) {
        routerToIndex()
    }
    // 对响应数据做点什么
    const {data: res} = response
    if (res.code === 500) {
        return -1
    }
    return res
})

Vue.use(ElementUI);


Vue.config.productionTip = false

new Vue({
    store,
    router,
    render: h => h(App),
}).$mount('#app')